size <- 12. Later this will be
the number of rows of the matrix.x <- rnorm( size ).x1 by adding (on average 10
times smaller) noise to x:
x1 <- x + rnorm( size )/10.x and x1 should be
close to 1.0: check this with function cor.x2 and x3 by
adding (other) noise to x.size <- 12
x <- rnorm( size )
x1 <- x + rnorm( size )/10
cor( x, x1 )
[1] 0.9915301
x2 <- x + rnorm( size )/10
x3 <- x + rnorm( size )/10
x1, x2 and x3
column-wise into a matrix using
m <- cbind( x1, x2, x3 ).m.m.heatmap( m, Colv = NA, Rowv = NA, scale = "none" ).m <- cbind( x1, x2, x3 )
class( m )
[1] "matrix" "array"
head( m )
x1 x2 x3
[1,] 1.0546811 0.9543218 0.9252153
[2,] -0.5946455 -0.4286210 -0.8394780
[3,] -1.2647519 -1.3554788 -1.4604135
[4,] 1.0985622 1.1501762 0.9433568
[5,] -0.9727524 -0.7626803 -0.7170948
[6,] 0.7041869 1.1084968 0.9207432
heatmap( m, Colv = NA, Rowv = NA, scale = "none" ) # high is dark red, low is yellow
# x1, x2, x3 follow similar color pattern, they should be correlated
y1…y4 (but not correlated with
x), of the same length size.m from columns
x1…x3,y1…y4 in some
random order.y <- rnorm( size )
y1 <- y + rnorm( size )/10
y2 <- y + rnorm( size )/10
y3 <- y + rnorm( size )/10
y4 <- y + rnorm( size )/10
m <- cbind( y4, y3, x2, y1, x1, x3, y2 )
heatmap( m, Colv = NA, Rowv = NA, scale = "none" ) # high is dark red, low is yellow
cc <- cor( m ) to build the matrix of correlation
coefficients between columns of m.round( cc, 3 ) to show this matrix with 3 digits
precision.cc <- cor( m )
round( cc, 3 ) #
y4 y3 x2 y1 x1 x3 y2
y4 1.000 0.995 -0.391 0.993 -0.364 -0.388 0.997
y3 0.995 1.000 -0.411 0.991 -0.387 -0.415 0.992
x2 -0.391 -0.411 1.000 -0.376 0.980 0.984 -0.403
y1 0.993 0.991 -0.376 1.000 -0.365 -0.381 0.988
x1 -0.364 -0.387 0.980 -0.365 1.000 0.980 -0.379
x3 -0.388 -0.415 0.984 -0.381 0.980 1.000 -0.404
y2 0.997 0.992 -0.403 0.988 -0.379 -0.404 1.000
heatmap( cc, symm = TRUE, scale = "none" )
# E.g. value for (row: x1, col: y1) is the corerlation of vectors x1, y1.
# Values of 1.0 are on the diagonal: e.g. x1 is perfectly correlated with x1.
# Correlations between x, x vectors are close to 1.0.
# Correlations between y, y vectors are close to 1.0.
# Correlations between x, y vectors are close to 0.0.
Copyright © 2023 Biomedical Data Sciences (BDS) | LUMC